Purpose

The purpose of this analysis document is to ensure the reproducability of the results by guiding the reader through the random forest analysis of the factors associated with the health of western redcedar.

Approach

Root data were shared by citizen scientists in the Wester Redcedar Dieback Map project on iNaturalist.

All of the data used in the below analyses are described in the Data Wrangle folder.

Limitations

Next steps

Data

The data used in the below visualizations are described in the Data Wrangle folder.

All tree health categories

## # A tibble: 11 x 2
## # Groups:   field.tree.canopy.symptoms [11]
##    field.tree.canopy.symptoms                             n
##    <fct>                                              <int>
##  1 Branch Dieback or 'Flagging'                          19
##  2 Browning Canopy                                       19
##  3 Extra Cone Crop                                        2
##  4 Healthy                                              403
##  5 Multiple Symptoms (please list in Notes)              17
##  6 New Dead Top (red or brown needles still attached)    33
##  7 Old Dead Top (needles already gone)                   83
##  8 Other (please describe in Notes)                       8
##  9 Thinning Canopy                                      118
## 10 Tree is dead                                          37
## 11 Yellowing Canopy                                      10

Filter Data

We need to filter the data to only include response and explanatory variables we’re interested in. For example, whether a sound clip was included in the iNat data is not important.

We also need to remove other response variables like “field.percent.canopy.affected….” so it is not used as a predictor for tree health.

Note it might be interesting to know if the user was an important factor in predicting if the tree is healthy/unhealthy.

There are also a number of factors that should probably be removed because they may be biasing the data. For example, only trees with the ‘other factor’ question may only be answered for unhealthy trees. We need to think about this a bit more.

Impute data

We continue to get the below error, but were able to work around it by imputing the data.

Error in randomForest.default(m, y, …) : Need at least two classes to do classification.

To impute the data we have to remove factors with >53 levels.

The below code lists the number of levels for the variables that are factors.

  • The following factors had more than 53 levels
    • “muaggatt_musym”
    • “muaggatt_muname”
    • “component_compname”
    • “component_geomdesc”
    • “component_taxclname”
    • “component_taxsubgrp”

Imputed data table

## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  46.46% 94.74% 94.74%100.00% 17.12% 70.59% 87.88% 75.90%100.00% 71.19% 94.59%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.79% 94.74% 94.74%100.00% 14.89% 70.59% 87.88% 77.11%100.00% 73.73% 94.59%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  44.99% 94.74%100.00%100.00% 14.14% 70.59% 87.88% 75.90%100.00% 72.03% 91.89%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.53% 94.74%100.00%100.00% 14.14% 82.35% 87.88% 75.90%100.00% 72.88% 94.59%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.66% 94.74% 94.74%100.00% 16.13% 76.47% 87.88% 72.29%100.00% 70.34% 97.30%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.53% 94.74%100.00%100.00% 15.38% 76.47% 87.88% 73.49%100.00% 71.19% 94.59%100.00%

Train and test data

Model

## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 47.95%
## Confusion matrix:
##                                                    Branch Dieback or 'Flagging'
## Branch Dieback or 'Flagging'                                                  1
## Browning Canopy                                                               0
## Extra Cone Crop                                                               0
## Healthy                                                                       3
## Multiple Symptoms (please list in Notes)                                      0
## New Dead Top (red or brown needles still attached)                            0
## Old Dead Top (needles already gone)                                           0
## Other (please describe in Notes)                                              0
## Thinning Canopy                                                               2
## Tree is dead                                                                  0
## Yellowing Canopy                                                              0
##                                                    Browning Canopy
## Branch Dieback or 'Flagging'                                     0
## Browning Canopy                                                  1
## Extra Cone Crop                                                  0
## Healthy                                                          1
## Multiple Symptoms (please list in Notes)                         1
## New Dead Top (red or brown needles still attached)               2
## Old Dead Top (needles already gone)                              0
## Other (please describe in Notes)                                 0
## Thinning Canopy                                                  0
## Tree is dead                                                     3
## Yellowing Canopy                                                 0
##                                                    Extra Cone Crop Healthy
## Branch Dieback or 'Flagging'                                     0      11
## Browning Canopy                                                  0      10
## Extra Cone Crop                                                  0       1
## Healthy                                                          0     252
## Multiple Symptoms (please list in Notes)                         0      10
## New Dead Top (red or brown needles still attached)               0      13
## Old Dead Top (needles already gone)                              0      22
## Other (please describe in Notes)                                 0       6
## Thinning Canopy                                                  0      36
## Tree is dead                                                     0      18
## Yellowing Canopy                                                 0       5
##                                                    Multiple Symptoms (please list in Notes)
## Branch Dieback or 'Flagging'                                                              0
## Browning Canopy                                                                           0
## Extra Cone Crop                                                                           0
## Healthy                                                                                   2
## Multiple Symptoms (please list in Notes)                                                  2
## New Dead Top (red or brown needles still attached)                                        0
## Old Dead Top (needles already gone)                                                       1
## Other (please describe in Notes)                                                          0
## Thinning Canopy                                                                           0
## Tree is dead                                                                              0
## Yellowing Canopy                                                                          0
##                                                    New Dead Top (red or brown needles still attached)
## Branch Dieback or 'Flagging'                                                                        0
## Browning Canopy                                                                                     2
## Extra Cone Crop                                                                                     0
## Healthy                                                                                             5
## Multiple Symptoms (please list in Notes)                                                            0
## New Dead Top (red or brown needles still attached)                                                  2
## Old Dead Top (needles already gone)                                                                 2
## Other (please describe in Notes)                                                                    0
## Thinning Canopy                                                                                     2
## Tree is dead                                                                                        2
## Yellowing Canopy                                                                                    1
##                                                    Old Dead Top (needles already gone)
## Branch Dieback or 'Flagging'                                                         2
## Browning Canopy                                                                      0
## Extra Cone Crop                                                                      1
## Healthy                                                                             10
## Multiple Symptoms (please list in Notes)                                             1
## New Dead Top (red or brown needles still attached)                                   4
## Old Dead Top (needles already gone)                                                 15
## Other (please describe in Notes)                                                     0
## Thinning Canopy                                                                     13
## Tree is dead                                                                         4
## Yellowing Canopy                                                                     1
##                                                    Other (please describe in Notes)
## Branch Dieback or 'Flagging'                                                      0
## Browning Canopy                                                                   0
## Extra Cone Crop                                                                   0
## Healthy                                                                           1
## Multiple Symptoms (please list in Notes)                                          0
## New Dead Top (red or brown needles still attached)                                0
## Old Dead Top (needles already gone)                                               0
## Other (please describe in Notes)                                                  0
## Thinning Canopy                                                                   0
## Tree is dead                                                                      0
## Yellowing Canopy                                                                  0
##                                                    Thinning Canopy Tree is dead
## Branch Dieback or 'Flagging'                                     2            0
## Browning Canopy                                                  0            3
## Extra Cone Crop                                                  0            0
## Healthy                                                         17            9
## Multiple Symptoms (please list in Notes)                         0            0
## New Dead Top (red or brown needles still attached)               2            1
## Old Dead Top (needles already gone)                             15            4
## Other (please describe in Notes)                                 0            0
## Thinning Canopy                                                 19            8
## Tree is dead                                                     4            0
## Yellowing Canopy                                                 2            0
##                                                    Yellowing Canopy class.error
## Branch Dieback or 'Flagging'                                      0   0.9375000
## Browning Canopy                                                   0   0.9375000
## Extra Cone Crop                                                   0   1.0000000
## Healthy                                                           1   0.1627907
## Multiple Symptoms (please list in Notes)                          0   0.8571429
## New Dead Top (red or brown needles still attached)                1   0.9200000
## Old Dead Top (needles already gone)                               0   0.7457627
## Other (please describe in Notes)                                  0   1.0000000
## Thinning Canopy                                                   2   0.7682927
## Tree is dead                                                      0   1.0000000
## Yellowing Canopy                                                  0   1.0000000

Concerns
  • Below are some concerns that should be investigated
  • The error rate is pretty high (~35%)
  • The MDS plots only represent a small percentage of the
Questions
  • Below are some questions to resolve moving forward
    • What is difference between MeanDecreaseAccuracy ad MeanDecreaseGini
      • MeanDecreaseAccuracy - how much the factor affected classification trees across, averaged for all 2000 trees?
      • MeanDecreaseGini - variation in influence of factor compared to other factors?

Explore different groupings

Five filtered Symptoms

Selected tree health categories

## # A tibble: 5 x 2
## # Groups:   field.tree.canopy.symptoms [5]
##   field.tree.canopy.symptoms                             n
##   <fct>                                              <int>
## 1 Healthy                                              403
## 2 New Dead Top (red or brown needles still attached)    33
## 3 Old Dead Top (needles already gone)                   83
## 4 Thinning Canopy                                      118
## 5 Tree is dead                                          37
Train and test data
Try creating random forest model from training data
## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 41.98%
## Confusion matrix:
##                                                    Healthy
## Healthy                                                252
## New Dead Top (red or brown needles still attached)      16
## Old Dead Top (needles already gone)                     21
## Thinning Canopy                                         46
## Tree is dead                                            13
##                                                    New Dead Top (red or brown needles still attached)
## Healthy                                                                                             4
## New Dead Top (red or brown needles still attached)                                                  5
## Old Dead Top (needles already gone)                                                                 2
## Thinning Canopy                                                                                     0
## Tree is dead                                                                                        3
##                                                    Old Dead Top (needles already gone)
## Healthy                                                                             17
## New Dead Top (red or brown needles still attached)                                   3
## Old Dead Top (needles already gone)                                                 22
## Thinning Canopy                                                                     24
## Tree is dead                                                                         8
##                                                    Thinning Canopy Tree is dead
## Healthy                                                         17            5
## New Dead Top (red or brown needles still attached)               1            2
## Old Dead Top (needles already gone)                             18            3
## Thinning Canopy                                                 13            4
## Tree is dead                                                     5            1
##                                                    class.error
## Healthy                                              0.1457627
## New Dead Top (red or brown needles still attached)   0.8148148
## Old Dead Top (needles already gone)                  0.6666667
## Thinning Canopy                                      0.8505747
## Tree is dead                                         0.9666667

Binary symptoms

Binary tree health categories

## # A tibble: 2 x 2
## # Groups:   field.tree.canopy.symptoms [2]
##   field.tree.canopy.symptoms     n
##   <fct>                      <int>
## 1 Healthy                      403
## 2 Unhealthy                    346
Train and test data
Try creating random forest model from training data
## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 28.52%
## Confusion matrix:
##           Healthy Unhealthy class.error
## Healthy       216        83   0.2775920
## Unhealthy      77       185   0.2938931

##     left daughter right daughter                split var   split point status
## 1               2              3              norm_Tmin02  2.150000e+00      1
## 2               4              5                 DD_18_at  7.750000e+02      1
## 3               6              7     muaggatt_brockdepmin  8.090696e+00      1
## 4               8              9             norm_Eref_sm  3.135000e+02      1
## 5              10             11               norm_RH_sp  7.250000e+01      1
## 6              12             13             norm_DD18_sm  6.000000e+01      1
## 7              14             15                  DD_0_wt  5.150000e+01      1
## 8              16             17            norm_DD_18_11  3.485000e+02      1
## 9              18             19    component_taxpartsize  2.642073e+08      1
## 10             20             21             norm_Eref_at  1.115000e+02      1
## 11              0              0                     <NA>  0.000000e+00     -1
## 12             22             23 component_slopelenusle_h  7.783250e+01      1
## 13             24             25                    PPT08  2.150000e+01      1
## 14             26             27               norm_CMI01  1.195000e+01      1
## 15             28             29               norm_CMI05 -1.295000e+00      1
## 16              0              0                     <NA>  0.000000e+00     -1
## 17              0              0                     <NA>  0.000000e+00     -1
## 18             30             31      component_aspectrep  4.955931e+01      1
## 19              0              0                     <NA>  0.000000e+00     -1
## 20             32             33      muaggatt_aws0150wta  1.306160e+01      1
## 21             34             35       muaggatt_hydgrpdcd  2.000000e+00      1
## 22              0              0                     <NA>  0.000000e+00     -1
## 23              0              0                     <NA>  0.000000e+00     -1
## 24              0              0                     <NA>  0.000000e+00     -1
## 25             36             37                 norm_EMT -1.175000e+01      1
## 26             38             39                 norm_EMT -1.155000e+01      1
## 27             40             41    component_taxgrtgroup  2.814747e+14      1
## 28             42             43                    RH_wt  8.100000e+01      1
## 29             44             45                   Tmin05  9.050000e+00      1
## 30             46             47                    CMI02  2.340500e+01      1
## 31             48             49              norm_Tmin01  5.500000e-01      1
## 32              0              0                     <NA>  0.000000e+00     -1
## 33              0              0                     <NA>  0.000000e+00     -1
## 34              0              0                     <NA>  0.000000e+00     -1
## 35              0              0                     <NA>  0.000000e+00     -1
## 36              0              0                     <NA>  0.000000e+00     -1
## 37              0              0                     <NA>  0.000000e+00     -1
## 38             50             51               norm_CMI04  3.005000e+00      1
## 39              0              0                     <NA>  0.000000e+00     -1
## 40             52             53               norm_PPT05  6.700000e+01      1
## 41             54             55                    DD_18  2.313500e+03      1
## 42              0              0                     <NA>  0.000000e+00     -1
## 43              0              0                     <NA>  0.000000e+00     -1
## 44             56             57                 norm_SHM  1.125500e+02      1
## 45              0              0                     <NA>  0.000000e+00     -1
## 46             58             59              norm_DD5_04  1.425000e+02      1
## 47             60             61         component_elev_h  4.602575e+02      1
## 48              0              0                     <NA>  0.000000e+00     -1
## 49             62             63     muaggatt_urbrecptwta  9.600000e-01      1
## 50              0              0                     <NA>  0.000000e+00     -1
## 51             64             65                 Aspect.x  2.727788e+02      1
## 52             66             67             norm_NFFD_sp  8.450000e+01      1
## 53             68             69                 norm_DD5  2.762500e+03      1
## 54              0              0                     <NA>  0.000000e+00     -1
## 55             70             71                   Tave10  1.165000e+01      1
## 56             72             73            Profilecurv.x  5.323393e-03      1
## 57             74             75            norm_DD_18_10  1.835000e+02      1
## 58             76             77      muaggatt_aws0100wta  2.136000e+01      1
## 59             78             79                   DD5_10  1.995000e+02      1
## 60             80             81         component_elev_r  1.170000e+02      1
## 61              0              0                     <NA>  0.000000e+00     -1
## 62             82             83                 norm_CMD  2.295000e+02      1
## 63             84             85       component_corsteel  3.000000e+00      1
## 64             86             87          component_map_r  9.803530e+02      1
## 65              0              0                     <NA>  0.000000e+00     -1
## 66              0              0                     <NA>  0.000000e+00     -1
## 67              0              0                     <NA>  0.000000e+00     -1
## 68             88             89               norm_CMI01  1.494500e+01      1
## 69              0              0                     <NA>  0.000000e+00     -1
## 70              0              0                     <NA>  0.000000e+00     -1
## 71             90             91                      MAP  2.524000e+03      1
## 72              0              0                     <NA>  0.000000e+00     -1
## 73              0              0                     <NA>  0.000000e+00     -1
## 74              0              0                     <NA>  0.000000e+00     -1
## 75              0              0                     <NA>  0.000000e+00     -1
## 76             92             93               norm_PPT06  9.450000e+01      1
## 77             94             95              norm_Eref11  1.650000e+01      1
## 78              0              0                     <NA>  0.000000e+00     -1
## 79             96             97       muaggatt_aws050wta  9.250000e+00      1
## 80              0              0                     <NA>  0.000000e+00     -1
## 81             98             99     muaggatt_wtdepannmin  6.532635e+01      1
## 82              0              0                     <NA>  0.000000e+00     -1
## 83            100            101                   Tmin12  9.000000e-01      1
## 84              0              0                     <NA>  0.000000e+00     -1
## 85              0              0                     <NA>  0.000000e+00     -1
## 86              0              0                     <NA>  0.000000e+00     -1
## 87            102            103            norm_DD_18_sm  1.435000e+02      1
## 88              0              0                     <NA>  0.000000e+00     -1
## 89              0              0                     <NA>  0.000000e+00     -1
## 90            104            105       muaggatt_engstafml  4.000000e+00      1
## 91              0              0                     <NA>  0.000000e+00     -1
## 92            106            107                 norm_EMT -1.275000e+01      1
## 93              0              0                     <NA>  0.000000e+00     -1
## 94              0              0                     <NA>  0.000000e+00     -1
## 95            108            109                  DD18_09  2.150000e+01      1
## 96            110            111               norm_PPT07  1.850000e+01      1
## 97            112            113            component_wei  5.636787e+01      1
## 98              0              0                     <NA>  0.000000e+00     -1
## 99            114            115              norm_Tmin08  1.185000e+01      1
## 100           116            117                   CMI_wt  9.454500e+01      1
## 101             0              0                     <NA>  0.000000e+00     -1
## 102             0              0                     <NA>  0.000000e+00     -1
## 103           118            119                   NFFD12  2.150000e+01      1
## 104           120            121                   Eref01  1.650000e+01      1
## 105           122            123      component_irrcapscl  2.000000e+00      1
## 106           124            125       component_irrcapcl  3.931599e+00      1
## 107           126            127                 norm_CMI  4.032000e+01      1
## 108             0              0                     <NA>  0.000000e+00     -1
## 109             0              0                     <NA>  0.000000e+00     -1
## 110             0              0                     <NA>  0.000000e+00     -1
## 111           128            129                 norm_MAP  1.099500e+03      1
## 112           130            131            norm_DD_18_wt  1.152000e+03      1
## 113             0              0                     <NA>  0.000000e+00     -1
## 114             0              0                     <NA>  0.000000e+00     -1
## 115             0              0                     <NA>  0.000000e+00     -1
## 116             0              0                     <NA>  0.000000e+00     -1
## 117             0              0                     <NA>  0.000000e+00     -1
## 118             0              0                     <NA>  0.000000e+00     -1
## 119             0              0                     <NA>  0.000000e+00     -1
## 120             0              0                     <NA>  0.000000e+00     -1
## 121             0              0                     <NA>  0.000000e+00     -1
## 122           132            133        muaggatt_engdwbll  4.000000e+00      1
## 123             0              0                     <NA>  0.000000e+00     -1
## 124           134            135               norm_CMI04  6.555000e+00      1
## 125           136            137                  NFFD_wt  4.050000e+01      1
## 126             0              0                     <NA>  0.000000e+00     -1
## 127             0              0                     <NA>  0.000000e+00     -1
## 128             0              0                     <NA>  0.000000e+00     -1
## 129           138            139               norm_PPT11  2.205000e+02      1
## 130             0              0                     <NA>  0.000000e+00     -1
## 131           140            141            Profilecurv.x -1.090274e-03      1
## 132             0              0                     <NA>  0.000000e+00     -1
## 133           142            143                   DD5_wt  1.625000e+02      1
## 134             0              0                     <NA>  0.000000e+00     -1
## 135           144            145               norm_PAS03  2.500000e+00      1
## 136             0              0                     <NA>  0.000000e+00     -1
## 137             0              0                     <NA>  0.000000e+00     -1
## 138             0              0                     <NA>  0.000000e+00     -1
## 139             0              0                     <NA>  0.000000e+00     -1
## 140             0              0                     <NA>  0.000000e+00     -1
## 141           146            147            norm_DD_18_03  3.075000e+02      1
## 142             0              0                     <NA>  0.000000e+00     -1
## 143             0              0                     <NA>  0.000000e+00     -1
## 144             0              0                     <NA>  0.000000e+00     -1
## 145             0              0                     <NA>  0.000000e+00     -1
## 146           148            149     muaggatt_brockdepmin  1.012805e+02      1
## 147             0              0                     <NA>  0.000000e+00     -1
## 148             0              0                     <NA>  0.000000e+00     -1
## 149             0              0                     <NA>  0.000000e+00     -1
##     prediction
## 1         <NA>
## 2         <NA>
## 3         <NA>
## 4         <NA>
## 5         <NA>
## 6         <NA>
## 7         <NA>
## 8         <NA>
## 9         <NA>
## 10        <NA>
## 11   Unhealthy
## 12        <NA>
## 13        <NA>
## 14        <NA>
## 15        <NA>
## 16     Healthy
## 17   Unhealthy
## 18        <NA>
## 19     Healthy
## 20        <NA>
## 21        <NA>
## 22     Healthy
## 23   Unhealthy
## 24   Unhealthy
## 25        <NA>
## 26        <NA>
## 27        <NA>
## 28        <NA>
## 29        <NA>
## 30        <NA>
## 31        <NA>
## 32     Healthy
## 33   Unhealthy
## 34   Unhealthy
## 35     Healthy
## 36   Unhealthy
## 37     Healthy
## 38        <NA>
## 39   Unhealthy
## 40        <NA>
## 41        <NA>
## 42   Unhealthy
## 43     Healthy
## 44        <NA>
## 45   Unhealthy
## 46        <NA>
## 47        <NA>
## 48   Unhealthy
## 49        <NA>
## 50     Healthy
## 51        <NA>
## 52        <NA>
## 53        <NA>
## 54   Unhealthy
## 55        <NA>
## 56        <NA>
## 57        <NA>
## 58        <NA>
## 59        <NA>
## 60        <NA>
## 61     Healthy
## 62        <NA>
## 63        <NA>
## 64        <NA>
## 65     Healthy
## 66   Unhealthy
## 67     Healthy
## 68        <NA>
## 69     Healthy
## 70   Unhealthy
## 71        <NA>
## 72     Healthy
## 73   Unhealthy
## 74     Healthy
## 75   Unhealthy
## 76        <NA>
## 77        <NA>
## 78     Healthy
## 79        <NA>
## 80     Healthy
## 81        <NA>
## 82     Healthy
## 83        <NA>
## 84     Healthy
## 85   Unhealthy
## 86   Unhealthy
## 87        <NA>
## 88   Unhealthy
## 89     Healthy
## 90        <NA>
## 91   Unhealthy
## 92        <NA>
## 93     Healthy
## 94   Unhealthy
## 95        <NA>
## 96        <NA>
## 97        <NA>
## 98     Healthy
## 99        <NA>
## 100       <NA>
## 101  Unhealthy
## 102    Healthy
## 103       <NA>
## 104       <NA>
## 105       <NA>
## 106       <NA>
## 107       <NA>
## 108  Unhealthy
## 109    Healthy
## 110  Unhealthy
## 111       <NA>
## 112       <NA>
## 113    Healthy
## 114  Unhealthy
## 115    Healthy
## 116    Healthy
## 117  Unhealthy
## 118    Healthy
## 119  Unhealthy
## 120  Unhealthy
## 121    Healthy
## 122       <NA>
## 123    Healthy
## 124       <NA>
## 125       <NA>
## 126  Unhealthy
## 127    Healthy
## 128    Healthy
## 129       <NA>
## 130  Unhealthy
## 131       <NA>
## 132  Unhealthy
## 133       <NA>
## 134  Unhealthy
## 135       <NA>
## 136  Unhealthy
## 137    Healthy
## 138  Unhealthy
## 139    Healthy
## 140    Healthy
## 141       <NA>
## 142  Unhealthy
## 143    Healthy
## 144    Healthy
## 145  Unhealthy
## 146       <NA>
## 147  Unhealthy
## 148    Healthy
## 149  Unhealthy
Visualize sample tree

Fit a single recursive partitioning or classification tree. Followed instructions from this youtube video.

Troubleshooting

Error in randomForest.default(m, y, …) : Need at least two classes to do classification.

I may be misunderstanding this error, but I think it is referring to the response variable?

The documentation here describes the error prompt when: if (classRF && !addclass && length(unique(y)) < 2) stop(“Need at least two classes to do classification.”)

It is possible some of the NA or -9999 values are causing issues.

We can try imputing the data, however this requires us to remove columns with more than 53 factors, which probably makes sense anyway.

Removing factors with more than 53 levels didn’t resolve the error from the randomForest command, but it did allow us to use the rfImpute command to impute our data.

Wow it actually worked if the data is imputed.